<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 大小为 K 且平均值大于或等于阈值的子数组数目 -->
    <script>
      var numOfSubarrays = function (arr, k, threshold) {
        let res = 0
        const len = arr.length
        const max = k * threshold
        let m = 0
        for (let i = 0; i < len; i++) {
          m += arr[i]
          if (i >= k) {
            m -= arr[i - k]
          }
          if (i >= k - 1 && m >= max) res++
        }
        return res
      }
      console.log(numOfSubarrays([11, 13, 17, 23, 29, 31, 7, 5, 2, 3], 3, 5))
    </script>
  </body>
</html>
